from django.shortcuts import render

# Create your views here.

from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.filters import OrderingFilter

from operation.models import SurgicalClassification, SurgicalDetails
from operation.ser import SurgicalClassificationSerializer, SurgicalDetailsSerializer

# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 排序配置
class CustomOrderingFilter(OrderingFilter):
    ordering_params = ('examination_name')

# 手术辅查 ListAPIView
class SurgicalClassificationListView(ListAPIView):
    serializer_class = SurgicalClassificationSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['examination_name']

    def get_queryset(self):
        return SurgicalClassification.objects.all()

# 辅查详情 ListAPIView
class SurgicalDetailsListView(ListAPIView):
    serializer_class = SurgicalDetailsSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['title']

    def get_queryset(self):
        return SurgicalDetails.objects.all()
